package com.test.demo;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.api.dom.java.InnerClass;
import org.mybatis.generator.api.dom.java.Method;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.internal.DefaultCommentGenerator;
import org.mybatis.generator.internal.util.StringUtility;

public class CommentGenerator extends DefaultCommentGenerator {

    private boolean suppressAllComments = true;

    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (this.suppressAllComments) {
            if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
                field.addJavaDocLine("//" + introspectedColumn.getRemarks());
            }
        } else {
            super.addFieldComment(field, introspectedTable, introspectedColumn);
        }
    }

    public void addGetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (this.suppressAllComments) {
            if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
//                method.addJavaDocLine("//get:" + introspectedColumn.getRemarks());
            }
        } else {
            super.addGetterComment(method, introspectedTable, introspectedColumn);
        }
    }

    public void addSetterComment(Method method, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        if (this.suppressAllComments) {
            if (StringUtility.stringHasValue(introspectedColumn.getRemarks())) {
//                method.addJavaDocLine("//set:" + introspectedColumn.getRemarks());
            }
        } else {
            super.addSetterComment(method, introspectedTable, introspectedColumn);
        }
    }

    public void addGeneralMethodComment(Method method, IntrospectedTable introspectedTable) {
        if (this.suppressAllComments) {
            return;
        }
        super.addGeneralMethodComment(method, introspectedTable);
    }

    public void addComment(XmlElement xmlElement) {
        if (this.suppressAllComments) {
            return;
        }
        super.addComment(xmlElement);
    }

    //下面是去掉Example中的注释

    public void addFieldComment(Field field, IntrospectedTable introspectedTable) {
        if (this.suppressAllComments) {
        } else {
            super.addFieldComment(field, introspectedTable);
        }
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable) {
        if (this.suppressAllComments) {
        } else {
            super.addClassComment(innerClass, introspectedTable);
        }
    }

    public void addClassComment(InnerClass innerClass, IntrospectedTable introspectedTable, boolean markAsDoNotDelete) {
        if (this.suppressAllComments) {
        } else {
            super.addClassComment(innerClass, introspectedTable, markAsDoNotDelete);
        }
    }


}
